﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using FileModelNS;

namespace FileModelTest
{
	[TestFixture]
	public class BaseUtilityTest
	{
		[Test]
		public void testConvertHexValueToByte()
		{
			byte[] result = BaseUtility.ConvertHexValueToByteArray("0x12345678");
			Assert.AreEqual(result, new byte[] {0x12, 0x34, 0x56, 0x78});
		}

		[Test]
		[ExpectedException(typeof(NonHexValueException))]
		public void testConvertHexValueToByte_NonHexValue1()
		{
			byte[] result = BaseUtility.ConvertHexValueToByteArray("12345678");
		}

		[Test]
		public void testConvertHexValueToByte_NonHexValue2()
		{
			try
			{
				byte[] result = BaseUtility.ConvertHexValueToByteArray("12345678");
			}
			catch( NonHexValueException e )
			{
				Assert.AreEqual( "12345678", e.Value);
			}
		}

		[Test]
		public void testCompareArray()
		{
			byte[] arr1 = new byte[4] { 0x12, 0x34, 0x56, 0x78 };
			byte[] arr2 = new byte[4] { 0x12, 0x34, 0x56, 0x78 };
			Assert.IsTrue(BaseUtility.CompareArray(arr1, arr2));

			byte[] arr3 = new byte[4] { 0x12, 0x55, 0x55, 0x55 };
			Assert.IsFalse(BaseUtility.CompareArray(arr1, arr3));
		}


	}
}
